<?php
if (!defined('KAIZEKU')) exit(42);
/**
 * WP-iStalker Chrome Min 
 * Template Class
 * 
 * PHP 5
 * 
 * @package	WordPress
 * @subpackage	wp-istalker-chrome-min
 * 
 * @category	Template
 * @author	Avice (ChaosKaizer) De'vereux <ck+wp-istalker-min@istalker.net>
 * @author	NH. Noah <noah+wp-istalker-min@kakkoi.net>
 * @copyright 	2007 - 2009 Avice De'vereux, NH. Noah
 * @license 	http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License v2 
 * @version 	CVS: $Id: template.php 13 2009-01-11 15:22:40Z chaoskaizer $
 * @since 	0.1
 */
 
/**
 * wpiTemplate
 * @since 0.1
 */
class wpiTemplate
{

	/**
	 * WP filter id
	 * used by wordpress filter hook	  
	 * @var int
	 */
	public $wp_filter_id;
		
	
	public function __construct()
	{
		$this->hook('send_headers','httpHeader');	// send http headers
		
		$this->hook('wp_head','docType',1);	// print dtd with priority 1
		
		$this->hook('wp_head','docHtml',1);	// print html tag root
		
		$this->hook('wp_head','docHead',1);	// print html head tag root
		
		$this->hook('wp_head','docTitle',2);	// print website title with priority 2
		
		$this->hook('wp_head','docBody',wpiTheme::LAST_PRIORITY+100);	// print head end tag and star of body tag
				
		if (WPI_SEO_LV <= 1){
			$this->hook(wpiFilter::BODY,'docNav',2);
		}	
	}


	/**
	 * public wpiTemplate::hook()
	 * Wrapper for add_action
	 * 
	 * @access public 
	 * @since 0.1
	 */	
	public function hook($filter_name, $methods, $priority=10, $args=1)
	{
		add_action($filter_name,array($this,$methods),$priority,$args);
	}
	
	
	/**
	 * void public wpiTemplate::httHeader()
	 * document HTTP header
	 * filter: wpiFilter::HTTP_HEADER
	 * 
	 * @uses wpiTemplate::contentLanguage()
	 * @access public 
	 * @return object wpiTemplate object 
	 * @since 0.1
	 */
	public function httpHeader()
	{	global $is_IE;
	
		$h = array();	// header content

        $h[] = 'Content-Style-Type: text/css';
        $h[] = 'Content-Script-Type: text/javascript';
        $h[] = 'Default-Style:'.wpiTheme::UID;
        $h[] = 'Content-Language:'.strtolower(self::contentLanguage());
        $h[] = 'Theme:'.wpiTheme::UID.'/'.wpiTheme::VERSION.'; url:'.wpiTheme::DOC_URL;	
        
        if ($is_IE && defined('CL_EMULATE_IE7')){
        	$h[] = 'X-UA-Compatible: IE=EmulateIE7';        
        }
		
		$h = apply_filters(wpiFilter::HTTP_HEADER, $h);

        if (has_count($h)){        		
        	foreach($h as $request) header($request);        
		}
			
		unset($h,$request); 
		return $this;			
	}
	

	/**
	 * void public wpiTemplate::docType()
	 * document content language
	 * defailt language "en-US"
	 * filter: wpiFilter::DOCTYPE
	 * 
	 * @category Template
	 * @access public 
	 * @since 0.1
	 */
	public function docType()
	{
		$output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ';
		$output .= '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'.PHP_EOL;
		
		echo apply_filters(wpiFilter::DOCTYPE,$output);		
	}
	
	
	/**
	 * void public wpiTemplate::docHTML()
	 * output document html root elements
	 * filter: language_attributes:wpiFilter::HTML_ROOT
	 * 
	 * @category Template
	 * @access public 
	 * @since 0.1
	 */
	public function docHTML()
	{
		$lang = get_bloginfo('language');
		$dir = get_bloginfo('text_direction'); 
		$dir = ('' != $dir)  ? $dir : 'ltr';
		
		$output = '<html xmlns="http://www.w3.org/1999/xhtml" dir="'.$dir.'" lang="'.$lang.'" xml:lang="'.$lang.'">'.PHP_EOL;	
		
		echo apply_filters(wpiFilter::HTML_ROOT,$output);
	}
	
	
	/**
	 * void public wpiTemplate::docHead()
	 * output document html head root elements
	 * filter: XMDP_PROFILE
	 * 
	 * @category Template
	 * @access public 
	 * @since 0.1
	 */
	public function docHead()
	{
		$xmdp = array();
		$xmdp[] = 'http://gmpg.org/xfn/11';		// XFN
		$xmdp[] = 'http://dublincore.org/documents/dcq-html/'; // dc
		
		$output = '<head profile="'.array_str($xmdp).'">'.PHP_EOL;
				
		echo apply_filters(wpiFilter::HTML_ROOT,$output);
	}
	

	/**
	 * void public wpiTemplate::docBody()
	 * output document html body root elements
	 * filter: BODY_ROOT
	 * 
	 * @category Template
	 * @access public 
	 * @since 0.1
	 */
	public function docBody()
	{		
		$output = '</head>'.PHP_EOL;
		$output .= '<body id="'.wpi_get_body_id().'" class="'.wpi_get_body_class().'">'.PHP_EOL;
		$output .= '<dl id="page">'.PHP_EOL;
				
		echo apply_filters(wpiFilter::BODY_ROOT,$output);
	}		
	
	
	/**
	 * void public wpiTemplate::docTitle()
	 * print website title
	 * filter: wpiFilter::SITE_TITLE
	 * 
	 * @category Template
	 * @access public 
	 * @uses _t HTML helper function
	 * @since 0.1
	 */
	public function docTitle()
	{ 		
		$output = _t('title',wp_title('&laquo;', false, 'right').WPI_BLOG_NAME).PHP_EOL;
				
		echo apply_filters(wpiFilter::SITE_TITLE,$output);		
	}


	/**
	 * void public wpiTemplate::docNav()
	 * print pages menu
	 * filter: wpiFilter::PAGES_NAV_MENU
	 * 
	 * @category Template
	 * @access public 
	 * @uses _t HTML helper function
	 * @since 0.1
	 */	
	public function docNav()
	{
		$pages_menu = wpi_get_pages_link();
		$output = _t('ul',$pages_menu,array('class'=>'nav'));
		$output = _t('div',$output,array('class'=>'container_16 clearfix'));
		$output = PHP_T._t('dd',$output,array('id'=>'wpi-nav')).PHP_EOL;
		
		echo apply_filters(wpiFilter::PAGES_NAV_MENU,$output);	
	}
	

	/**
	 * void static wpiTemplate::contentLanguage()
	 * document content language
	 * defailt language "en-US"
	 * filter: wpiFilter::CONTENT_LANGUAGE
	 * 
	 * @since 0.1
	 */
	public static function contentLanguage()
	{
		$lang = get_option('rss_language');		
		$lang = ($lang == 'en') ? 'en-US' : 'en';
		
		return apply_filters(wpiFilter::CONTENT_LANGUAGE,$lang);		
	}
	
		
	public function __destruct(){ unset($this); }
	
	
	public function __clone(){}
}    
?>